package com.cx.mall.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
@Component
public class AutoFieldFillHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // 自动填充创建时间字段:对哪个对象的什么属性进行填充
        strictInsertFill(metaObject,"createTime",LocalDateTime.class, LocalDateTime.now());
        // 自动填充修改时间字段
        strictInsertFill(metaObject,"updateTime", LocalDateTime.class, LocalDateTime.now());
        // 自动填充逻辑删除字段deleted:0未删除
        strictInsertFill(metaObject,"deleted",Integer.class,0);
        // 自动填充状态:0 正常
        strictInsertFill(metaObject,"status",Integer.class,0);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //自动填充修改时间字段
        strictInsertFill(metaObject,"updateTime", LocalDateTime.class, LocalDateTime.now());
    }
}
